package b.f;

import java.util.ConcurrentModificationException;
import java.util.Map;

/* compiled from: SimpleArrayMap */
public class h<K, V> {
    public static Object[] d;
    public static int e;
    public static Object[] f;
    public static int g;
    public int[] a;
    public Object[] b;
    public int c;

    public h() {
        this.a = d.a;
        this.b = d.c;
        this.c = 0;
    }

    public static void c(int[] iArr, Object[] objArr, int i) {
        Class cls = h.class;
        int i2;
        if (iArr.length == 8) {
            synchronized (cls) {
                if (g < 10) {
                    objArr[0] = f;
                    objArr[1] = iArr;
                    for (i2 = (i << 1) - 1; i2 >= 2; i2--) {
                        objArr[i2] = null;
                    }
                    f = objArr;
                    g++;
                }
            }
        } else if (iArr.length == 4) {
            synchronized (cls) {
                if (e < 10) {
                    objArr[0] = d;
                    objArr[1] = iArr;
                    for (i2 = (i << 1) - 1; i2 >= 2; i2--) {
                        objArr[i2] = null;
                    }
                    d = objArr;
                    e++;
                }
            }
        }
    }

    public final void a(int i) {
        Class cls = h.class;
        Object[] objArr;
        if (i == 8) {
            synchronized (cls) {
                objArr = f;
                if (objArr != null) {
                    this.b = objArr;
                    f = (Object[]) objArr[0];
                    this.a = (int[]) objArr[1];
                    objArr[1] = null;
                    objArr[0] = null;
                    g--;
                    return;
                }
            }
        } else if (i == 4) {
            synchronized (cls) {
                objArr = d;
                if (objArr != null) {
                    this.b = objArr;
                    d = (Object[]) objArr[0];
                    this.a = (int[]) objArr[1];
                    objArr[1] = null;
                    objArr[0] = null;
                    e--;
                    return;
                }
            }
        }
        this.a = new int[i];
        this.b = new Object[(i << 1)];
    }

    public void b(int i) {
        int i2 = this.c;
        int[] iArr = this.a;
        if (iArr.length < i) {
            Object[] objArr = this.b;
            a(i);
            if (this.c > 0) {
                System.arraycopy(iArr, 0, this.a, 0, i2);
                System.arraycopy(objArr, 0, this.b, 0, i2 << 1);
            }
            c(iArr, objArr, i2);
        }
        if (this.c != i2) {
            throw new ConcurrentModificationException();
        }
    }

    public void clear() {
        int i = this.c;
        if (i > 0) {
            int[] iArr = this.a;
            Object[] objArr = this.b;
            this.a = d.a;
            this.b = d.c;
            this.c = 0;
            c(iArr, objArr, i);
        }
        if (this.c > 0) {
            throw new ConcurrentModificationException();
        }
    }

    public boolean containsKey(Object obj) {
        return e(obj) >= 0;
    }

    public boolean containsValue(Object obj) {
        return g(obj) >= 0;
    }

    public int d(Object obj, int i) {
        int i2 = this.c;
        if (i2 == 0) {
            return -1;
        }
        try {
            int a = d.a(this.a, i2, i);
            if (a < 0 || obj.equals(this.b[a << 1])) {
                return a;
            }
            int i3 = a + 1;
            while (i3 < i2 && this.a[i3] == i) {
                if (obj.equals(this.b[i3 << 1])) {
                    return i3;
                }
                i3++;
            }
            a--;
            while (a >= 0 && this.a[a] == i) {
                if (obj.equals(this.b[a << 1])) {
                    return a;
                }
                a--;
            }
            return ~i3;
        } catch (ArrayIndexOutOfBoundsException unused) {
            throw new ConcurrentModificationException();
        }
    }

    public int e(Object obj) {
        return obj == null ? f() : d(obj, obj.hashCode());
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        int i;
        Object h;
        Object k;
        Object obj2;
        if (obj instanceof h) {
            h hVar = (h) obj;
            if (this.c != hVar.c) {
                return false;
            }
            i = 0;
            while (i < this.c) {
                try {
                    h = h(i);
                    k = k(i);
                    obj2 = hVar.get(h);
                    if (k == null) {
                        if (obj2 != null || !hVar.containsKey(h)) {
                            return false;
                        }
                    } else if (!k.equals(obj2)) {
                        return false;
                    }
                    i++;
                } catch (ClassCastException | NullPointerException unused) {
                    return false;
                }
            }
            return true;
        }
        if (obj instanceof Map) {
            Map map = (Map) obj;
            if (this.c != map.size()) {
                return false;
            }
            i = 0;
            while (i < this.c) {
                try {
                    h = h(i);
                    k = k(i);
                    obj2 = map.get(h);
                    if (k == null) {
                        if (obj2 != null || !map.containsKey(h)) {
                            return false;
                        }
                    } else if (!k.equals(obj2)) {
                        return false;
                    }
                    i++;
                } catch (ClassCastException | NullPointerException unused2) {
                }
            }
            return true;
        }
        return false;
    }

    public int f() {
        int i = this.c;
        if (i == 0) {
            return -1;
        }
        try {
            int a = d.a(this.a, i, 0);
            if (a < 0 || this.b[a << 1] == null) {
                return a;
            }
            int i2 = a + 1;
            while (i2 < i && this.a[i2] == 0) {
                if (this.b[i2 << 1] == null) {
                    return i2;
                }
                i2++;
            }
            a--;
            while (a >= 0 && this.a[a] == 0) {
                if (this.b[a << 1] == null) {
                    return a;
                }
                a--;
            }
            return ~i2;
        } catch (ArrayIndexOutOfBoundsException unused) {
            throw new ConcurrentModificationException();
        }
    }

    public int g(Object obj) {
        int i = this.c * 2;
        Object[] objArr = this.b;
        if (obj == null) {
            for (int i2 = 1; i2 < i; i2 += 2) {
                if (objArr[i2] == null) {
                    return i2 >> 1;
                }
            }
        } else {
            for (int i3 = 1; i3 < i; i3 += 2) {
                if (obj.equals(objArr[i3])) {
                    return i3 >> 1;
                }
            }
        }
        return -1;
    }

    public V get(Object obj) {
        return getOrDefault(obj, null);
    }

    public V getOrDefault(Object obj, V v) {
        int e = e(obj);
        return e >= 0 ? this.b[(e << 1) + 1] : v;
    }

    public K h(int i) {
        return this.b[i << 1];
    }

    public int hashCode() {
        int[] iArr = this.a;
        Object[] objArr = this.b;
        int i = this.c;
        int i2 = 1;
        int i3 = 0;
        int i4 = 0;
        while (i3 < i) {
            Object obj = objArr[i2];
            i4 += (obj == null ? 0 : obj.hashCode()) ^ iArr[i3];
            i3++;
            i2 += 2;
        }
        return i4;
    }

    public V i(int i) {
        Object[] objArr = this.b;
        int i2 = i << 1;
        V v = objArr[i2 + 1];
        int i3 = this.c;
        int i4 = 0;
        if (i3 <= 1) {
            c(this.a, objArr, i3);
            this.a = d.a;
            this.b = d.c;
        } else {
            int i5 = i3 - 1;
            int[] iArr = this.a;
            int i6 = 8;
            if (iArr.length <= 8 || i3 >= iArr.length / 3) {
                int i7;
                Object[] objArr2;
                if (i < i5) {
                    i7 = i + 1;
                    i4 = i5 - i;
                    System.arraycopy(iArr, i7, iArr, i, i4);
                    objArr2 = this.b;
                    System.arraycopy(objArr2, i7 << 1, objArr2, i2, i4 << 1);
                }
                objArr2 = this.b;
                i7 = i5 << 1;
                objArr2[i7] = null;
                objArr2[i7 + 1] = null;
            } else {
                if (i3 > 8) {
                    i6 = i3 + (i3 >> 1);
                }
                a(i6);
                if (i3 == this.c) {
                    if (i > 0) {
                        System.arraycopy(iArr, 0, this.a, 0, i);
                        System.arraycopy(objArr, 0, this.b, 0, i2);
                    }
                    if (i < i5) {
                        i4 = i + 1;
                        i6 = i5 - i;
                        System.arraycopy(iArr, i4, this.a, i, i6);
                        System.arraycopy(objArr, i4 << 1, this.b, i2, i6 << 1);
                    }
                } else {
                    throw new ConcurrentModificationException();
                }
            }
            i4 = i5;
        }
        if (i3 == this.c) {
            this.c = i4;
            return v;
        }
        throw new ConcurrentModificationException();
    }

    public boolean isEmpty() {
        return this.c <= 0;
    }

    public V j(int i, V v) {
        i = (i << 1) + 1;
        Object[] objArr = this.b;
        V v2 = objArr[i];
        objArr[i] = v;
        return v2;
    }

    public V k(int i) {
        return this.b[(i << 1) + 1];
    }

    public V put(K k, V v) {
        int f;
        int i;
        int i2 = this.c;
        if (k == null) {
            f = f();
            i = 0;
        } else {
            f = k.hashCode();
            i = f;
            f = d(k, f);
        }
        Object[] objArr;
        if (f >= 0) {
            int i3 = (f << 1) + 1;
            objArr = this.b;
            V v2 = objArr[i3];
            objArr[i3] = v;
            return v2;
        }
        f = ~f;
        int[] iArr = this.a;
        if (i2 >= iArr.length) {
            int i4 = 4;
            if (i2 >= 8) {
                i4 = (i2 >> 1) + i2;
            } else if (i2 >= 4) {
                i4 = 8;
            }
            Object[] objArr2 = this.b;
            a(i4);
            if (i2 == this.c) {
                int[] iArr2 = this.a;
                if (iArr2.length > 0) {
                    System.arraycopy(iArr, 0, iArr2, 0, iArr.length);
                    System.arraycopy(objArr2, 0, this.b, 0, objArr2.length);
                }
                c(iArr, objArr2, i2);
            } else {
                throw new ConcurrentModificationException();
            }
        }
        if (f < i2) {
            int[] iArr3 = this.a;
            int i5 = f + 1;
            System.arraycopy(iArr3, f, iArr3, i5, i2 - f);
            Object[] objArr3 = this.b;
            System.arraycopy(objArr3, f << 1, objArr3, i5 << 1, (this.c - f) << 1);
        }
        int i6 = this.c;
        if (i2 == i6) {
            int[] iArr4 = this.a;
            if (f < iArr4.length) {
                iArr4[f] = i;
                objArr = this.b;
                f <<= 1;
                objArr[f] = k;
                objArr[f + 1] = v;
                this.c = i6 + 1;
                return null;
            }
        }
        throw new ConcurrentModificationException();
    }

    public V putIfAbsent(K k, V v) {
        V orDefault = getOrDefault(k, null);
        return orDefault == null ? put(k, v) : orDefault;
    }

    public V remove(Object obj) {
        int e = e(obj);
        return e >= 0 ? i(e) : null;
    }

    public V replace(K k, V v) {
        int e = e(k);
        return e >= 0 ? j(e, v) : null;
    }

    public int size() {
        return this.c;
    }

    public String toString() {
        if (isEmpty()) {
            return "{}";
        }
        StringBuilder stringBuilder = new StringBuilder(this.c * 28);
        stringBuilder.append('{');
        for (int i = 0; i < this.c; i++) {
            if (i > 0) {
                stringBuilder.append(", ");
            }
            h h = h(i);
            String str = "(this Map)";
            if (h != this) {
                stringBuilder.append(h);
            } else {
                stringBuilder.append(str);
            }
            stringBuilder.append('=');
            h = k(i);
            if (h != this) {
                stringBuilder.append(h);
            } else {
                stringBuilder.append(str);
            }
        }
        stringBuilder.append('}');
        return stringBuilder.toString();
    }

    public boolean remove(Object obj, Object obj2) {
        int e = e(obj);
        if (e >= 0) {
            Object k = k(e);
            if (obj2 == k || (obj2 != null && obj2.equals(k))) {
                i(e);
                return true;
            }
        }
        return false;
    }

    public boolean replace(K k, V v, V v2) {
        int e = e(k);
        if (e >= 0) {
            V k2 = k(e);
            if (k2 == v || (v != null && v.equals(k2))) {
                j(e, v2);
                return true;
            }
        }
        return false;
    }

    public h(int i) {
        if (i == 0) {
            this.a = d.a;
            this.b = d.c;
        } else {
            a(i);
        }
        this.c = 0;
    }
}
